package com.apr.mapper;

import com.apr.bean.Department;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 指定这是一个操作数据库的mapper
 *
 * @author zlj
 */
// @Mapper
public interface DeptMapper {

    /**
     * 根据ID查询部门信息
     * @param id
     * @return
     */
    @Select("SELECT * FROM department where id = #{id}")
    Department getDepartmentById(Integer id);

    /**
     * 插入部门信息
     *
     * @Options(useGeneratedKeys = true, keyProperty = "id")：返回自增主键的值
     * @param department
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("INSERT INTO department(department_name) values(#{departmentName})")
    int insertDepartment(Department department);

    /**
     * 根据ID删除部门信息
     * @param id
     * @return
     */
    @Delete("DELETE FROM department where id = #{id}")
    int deleteDepartment(Integer id);

    /**
     * 根据ID修改部门信息
     * @param department
     * @return
     */
    @Update("UPDATE department set department_name = #{departmentName} WHERE id = #{id}")
    int updateDepartment(Department department);
}
